/**
 * 选择排序
 */
Array.prototype.selectionSort = function() {
  for (let i = 0; i < this.length - 1; i++) {
    let minimumValueIndex = i;
    for (let j = i; j < this.length; j++) {
      if (this[j] < this[minimumValueIndex]) {
        minimumValueIndex = j;
      }
    }
    if (i !== minimumValueIndex) {
      let aux = this[minimumValueIndex];
      this[minimumValueIndex] = this[i];
      this[i] = aux;
    }
  }
  return this;
};

console.log([5, 4, 3, 2, 1].selectionSort().toString()); // 1,2,3,4,5
